package com.anyou.mall.pla.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.pla.domain.HotSearch;
import com.anyou.mall.pla.service.IHotSearchService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 热门搜索关键词Controller
 *
 * @author gaochaohao
 * @date 2022-03-21
 */
@Api(tags = "热门搜索关键词")
@RestController
@RequestMapping("/pla/hotSearch")
public class HotSearchController extends BaseController
{
    @Autowired
    private IHotSearchService hotSearchService;

    /**
     * 查询热门搜索关键词列表
     */
    @ApiOperation("查询热门搜索关键词列表")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:list')")
    @GetMapping("/list")
    public TableDataInfo<List<HotSearch>> list(HotSearch hotSearch)
    {
        startPage();
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        return getDataTable(list);
    }

    /**
     * 导出热门搜索关键词列表
     */
    @ApiOperation("导出热门搜索关键词列表")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:export')")
    @Log(title = "热门搜索关键词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotSearch hotSearch)
    {
        List<HotSearch> list = hotSearchService.selectHotSearchList(hotSearch);
        ExcelUtil<HotSearch> util = new ExcelUtil<HotSearch>(HotSearch.class);
        util.exportExcel(response, list, "热门搜索关键词数据");
    }

    /**
     * 获取热门搜索关键词详细信息
     */
    @ApiOperation("获取热门搜索关键词详细信息")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:query')")
    @GetMapping(value = "/{searchId}")
    public ApiResult<HotSearch> getInfo(@PathVariable("searchId") Long searchId)
    {
        return ApiResult.success(hotSearchService.selectHotSearchBySearchId(searchId));
    }

    /**
     * 新增热门搜索关键词
     */
    @ApiOperation("新增热门搜索关键词")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:add')")
    @Log(title = "热门搜索关键词", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody HotSearch hotSearch)
    {
        return ApiResult.success(hotSearchService.insertHotSearch(hotSearch));
    }

    /**
     * 修改热门搜索关键词
     */
    @ApiOperation("修改热门搜索关键词")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:edit')")
    @Log(title = "热门搜索关键词", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody HotSearch hotSearch)
    {
        return ApiResult.success(hotSearchService.updateHotSearch(hotSearch));
    }

    /**
     * 删除热门搜索关键词
     */
    @ApiOperation("删除热门搜索关键词")
    @PreAuthorize("@ss.hasPermi('pla:hotSearch:remove')")
    @Log(title = "热门搜索关键词", businessType = BusinessType.DELETE)
    @DeleteMapping("/{searchIds}")
    public ApiResult remove(@PathVariable Long[] searchIds)
    {
        return ApiResult.success(hotSearchService.deleteHotSearchBySearchIds(searchIds));
    }
}
